home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_ports.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  10.3 KB  |  315 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. int  portcnt;
  33.  
  34. static APTR PortPool = NULL;
  35.  
  36. __asm __saveds LONG portlist_dspfunc(register __a2 char **array, register __a1 struct PortEntry *portentry, register __a0 struct Hook *hook)
  37. {
  38.    if (portentry) {
  39.       *array++ = portentry->pt_address;
  40.       *array++ = portentry->pt_name;
  41.       *array++ = portentry->pt_pri;
  42.       *array++ = portentry->pt_flags;
  43.       *array++ = portentry->pt_sigbit;
  44.       *array++ = portentry->pt_sigtask;
  45.       *array   = NULL;
  46.    } else {
  47.       *array++ = ESC "bAddress";
  48.       *array++ = ESC "bln_Name";
  49.       *array++ = ESC "bln_Pri";
  50.       *array++ = ESC "bmp_Flags";
  51.       *array++ = ESC "bmp_SigBit";
  52.       *array++ = ESC "bmp_SigTask";
  53.       *array   = NULL;
  54.    }
  55.    return(0);
  56. }
  57.  
  58. struct Hook portlist_dsphook = {
  59.  {NULL, NULL},
  60.  (ULONG (* )())portlist_dspfunc,
  61.  NULL, NULL
  62. };
  63.  
  64. void FreePorts (void)
  65. {
  66.     MyFreePoolStructs(&PortPool, porttext, NULL, portlist);
  67. }
  68.  
  69. int GetPorts (struct PortEntry **first) {
  70.    struct   MsgPort     *port;
  71.    struct   PortEntry   *portentry,*previous = NULL;
  72.  
  73.    int portcnt = 0;
  74.    *first = 0;
  75.  
  76.    if (!PortPool) PortPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  77.  
  78.    if (clientstate) {
  79.       if (SendDaemon ("GetPortList")) {
  80.          while ((portentry = tbAllocPooled(PortPool, sizeof(struct PortEntry))) \
  81.            && (ReceiveDecodedEntry ((UBYTE *) portentry, sizeof (struct PortEntry)))) {
  82.             IsHex (portentry->pt_address, (long *) &portentry->pt_adr);
  83.  
  84.             if (! *first)
  85.                *first = portentry;
  86.             if (previous)
  87.                previous->pt_next = portentry;
  88.  
  89.             portcnt++;
  90.             previous = portentry;
  91.          }
  92.       }
  93.    } else {
  94.       port = FIRSTPORT;
  95.    
  96.       while ((port->mp_Node.ln_Succ != 0) && (portentry = tbAllocPooled(PortPool, sizeof(struct PortEntry)))) {
  97.          if (! *first)
  98.             *first = portentry;
  99.          if (previous)
  100.             previous->pt_next = portentry;
  101.    
  102.          portentry->pt_adr = port;
  103.    
  104.          _sprintf (portentry->pt_address, "$%08lx", port);
  105.          strncpy (portentry->pt_name, nonetest (port->mp_Node.ln_Name), 25);
  106.          _sprintf (portentry->pt_pri, "%4ld ", port->mp_Node.ln_Pri);
  107.          _sprintf (portentry->pt_sigbit, "%3ld ", port->mp_SigBit);
  108.          strncpy (portentry->pt_sigtask, nonetest (GetTaskName ((struct Task *) port->mp_SigTask)), NODENAMELENGTH - 1);
  109.          healstring (portentry->pt_sigtask);
  110.          switch (port->mp_Flags) {
  111.             case PA_SIGNAL : strcpy(portentry->pt_flags, "signal"); break;
  112.             case PA_SOFTINT: strcpy(portentry->pt_flags, "softint"); break;
  113.             case PA_IGNORE : strcpy(portentry->pt_flags, "ignore"); break;
  114.          }
  115.    
  116.          portcnt++;
  117.          previous = portentry;
  118.          port = (struct MsgPort *) port->mp_Node.ln_Succ;
  119.       }
  120.    }
  121.    return (portcnt);
  122. }
  123.  
  124. void PrintPorts (char *filename) {
  125.    int i=1;
  126.    BPTR handle;
  127.    struct PortEntry *entryp = NULL;
  128.  
  129.    handle = HandlePrintStart (filename);
  130.    if ((handle) && (PrintOneLine (handle, "\n  Address  Name                       Pri SigBit SigTask\n\n"))) {
  131.       if (! WI_Ports) {
  132.          i = GetPorts (&entryp);
  133.       }
  134.       if (i) {
  135.          for (i=0;;i++) {
  136.             if (WI_Ports)
  137.                DoMethod (portlist,MUIM_List_GetEntry,i,&entryp);
  138.             if (!entryp) break;
  139.  
  140.             _sprintf (tmpstr2, " %s %-25.25s %4s %3s   %-26.26s\n", entryp->pt_address, entryp->pt_name, entryp->pt_pri, entryp->pt_sigbit, entryp->pt_sigtask);
  141.             if (! (PrintOneLine (handle, tmpstr2)))
  142.                break;
  143.  
  144.             if (! WI_Ports)
  145.                entryp = entryp->pt_next;
  146.          }
  147.       }
  148.    }
  149.    HandlePrintStop();
  150. }
  151.  
  152. void ShowPorts (void) {
  153.    struct   PortEntry   *port;
  154.  
  155.    ApplicationSleep();
  156.    set(portlist,MUIA_List_Quiet,TRUE);
  157.    set(portlist,MUIA_List_CompareHook,portlist_cmphook_ptr);
  158.    set(BT_PortRemove, MUIA_Disabled, TRUE);
  159.    set(BT_PortPriority, MUIA_Disabled, TRUE);
  160.    set(BT_PortMore, MUIA_Disabled, TRUE);
  161.  
  162.    FreePorts();
  163.    portcnt = GetPorts (&port);
  164.  
  165.    while (port) {
  166.       InsertSortedEntry (portlist, (APTR *) &port);
  167.       port = port->pt_next;
  168.    }
  169.  
  170.    SetCountText (portcount, portcnt);
  171.    AwakeApplication();
  172.    set(portlist,MUIA_List_Quiet,FALSE);
  173. }
  174.  
  175. void SendPortList (void) {
  176.    struct   PortEntry   *port;
  177.  
  178.    FreePorts();
  179.    GetPorts (&port);
  180.  
  181.    while (port) {
  182.       SendEncodedEntry ((UBYTE *) port, sizeof (struct PortEntry));
  183.       port = port->pt_next;
  184.    }
  185.    FreePorts();
  186. }
  187.  
  188. void GetPortMore (struct MsgPort *port) {
  189.    unsigned char  *title = "PORT: ";
  190.    struct   WinFree  *ptr;
  191.  
  192.    APTR portmoretext0,portmoretext1,portmoretext2a,portmoretext2b,portmoretext3;
  193.    APTR portmoretext4,portmoretext5;
  194.  
  195.    if (ptr = AllocWinFree()) {
  196.       ptr->wf_Window = (APTR) WindowObject,
  197.  
  198. //      MUIA_Window_SizeGadget, FALSE,
  199.       MUIA_HelpNode, PortsText,
  200.       MUIA_Window_ID, MakeDetailID('.','P','O','R'),
  201.       WindowContents, HGroup,
  202.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  203.             Child, MyLabel2 ("Name:"),
  204.             Child, MyVSpace(0),
  205.             Child, MyLabel2 ("Address:\nPri:\nType:"),
  206.             Child, MyVSpace(0),
  207.             Child, MyLabel2 ("TaskName:"),
  208.             Child, MyLabel2 ("MsgList:\nHead:"),
  209.          End,
  210.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  211.             Child, portmoretext0 = MyTextObject(),
  212.             Child, HGroup,
  213.                Child, portmoretext1 = MyTextObject2(),
  214.                Child, VGroup,
  215.                   Child, MyLabel ("Flags:"),
  216.                   Child, MyLabel ("SigBit:\nSigTask:"),
  217.                End,
  218.                Child, VGroup, MUIA_Group_SameWidth, TRUE, MUIA_Weight, 0,
  219.                   Child, portmoretext2a = KeyButtonF ('b', port->mp_Flags),
  220.                   Child, portmoretext2b = MyTextObject(),
  221.                End,
  222.             End,
  223.             Child, portmoretext3 = MyTextObject(),
  224.             Child, HGroup,
  225.                Child, portmoretext4 = MyTextObject2(),
  226.                Child, MyLabel ("Tail:\nTailPred:"),
  227.                Child, portmoretext5 = MyTextObject2(),
  228.             End,
  229.          End,
  230.       End, End;
  231.  
  232.       if (ptr->wf_Window) {
  233.          MySetContents (portmoretext1, ESC "r$%08lx\n" ESC "c%ld\n" ESC "c%s", port, port->mp_Node.ln_Pri, GetNodeType (port->mp_Node.ln_Type));
  234.          MySetContents (portmoretext2b, ESC "c%ld\n" ESC "r$%08lx", port->mp_SigBit, port->mp_SigTask);
  235.          MySetContents (portmoretext4, ESC "r$%08lx\n$%08lx", &port->mp_MsgList, port->mp_MsgList.lh_Head);
  236.          MySetContents (portmoretext5, ESC "r$%08lx\n$%08lx", port->mp_MsgList.lh_Tail, port->mp_MsgList.lh_TailPred);
  237.  
  238.          HandleFlagsButtonPressed (portmoretext2a, ptr, "(PORT)", "mp_Flags", port->mp_Flags, NULL, (struct MaskedLongFlag *) &mp_flags, 'b');
  239.          HandleWindowOpen (ptr, title, port->mp_Node.ln_Name);
  240.          MySetContentsHealed (portmoretext0, "%s", port->mp_Node.ln_Name);
  241.          MySetContentsHealed (portmoretext3, "%s", nonetest (GetTaskName (port->mp_SigTask)));
  242.          HandleWindowClose (ptr);
  243.       }
  244.    }
  245. }
  246.  
  247.  
  248. APTR WI_Ports, portlist, porttext, portcount, CY_PortSort;
  249. int  portsortstate = 0;
  250. APTR BT_PortUpdate, BT_PortPrint, BT_PortRemove, BT_PortPriority, BT_PortMore, BT_PortExit;
  251.  
  252. APTR PortSortList[] = {
  253.    &tasklist_cmpprihook,
  254.    &list_cmpnamehook,
  255.    &tasklist_cmpaddresshook,
  256.    NULL
  257. };
  258.  
  259. static const char *CYA_PortSortText[] = {
  260.    "priority",
  261.    "name",
  262.    "address",
  263.    NULL
  264. };
  265.  
  266. char ports_title[WINDOWTITLELEN];
  267.  
  268. void PortsWindow (BOOL state) {
  269.    if (state) {
  270.       if (WI_Ports) {
  271.          ShowPorts();
  272.       } else {
  273.          WI_Ports = WindowObject,
  274.          MUIA_Window_Title, MyGetWindowTitle (ports_title, "PORTS"),
  275.          MUIA_HelpNode, PortsText,
  276.          MUIA_Window_ID, MakeListID('P','O','R','T'),
  277.          WindowContents, VGroup,
  278.             Child, portlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8,COL=4 DELTA=8 P=\33c,COL=5",&portlist_dsphook),
  279.             Child, MyBelowSortedListview (&porttext, &portcount, &CY_PortSort, CYA_PortSortText, portsortstate),
  280.             Child, MyVSpace(2),
  281.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  282.                Child, BT_PortUpdate   = KeyButtonA (UpdateText  ,ID_PORTUPDATE),
  283.                Child, BT_PortPrint    = KeyButtonA (PrintText   ,ID_PORTPRINT),
  284.                Child, BT_PortRemove   = KeyButtonA (RemoveText  ,ID_PORTREMOVE),
  285.                Child, BT_PortPriority = KeyButtonA (PriorityText,ID_PORTPRIORITY),
  286.                Child, BT_PortMore     = KeyButtonA (MoreText    ,ID_PORTMORE),
  287.                Child, BT_PortExit     = KeyButtonA (ExitText    ,ID_PORTEXIT),
  288.             End,
  289.          End, End;
  290.  
  291.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Ports);
  292.          DoMethod (WI_Ports,MUIM_Window_SetCycleChain,portlist,CY_PortSort,BT_PortUpdate,BT_PortPrint,BT_PortRemove,BT_PortPriority,BT_PortMore,BT_PortExit,NULL);
  293.          DoMethod (CY_PortSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_PORTSORT);
  294.  
  295.          SetCloseRequest (WI_Ports,ID_PORTEXIT);
  296.          SetListActive (portlist,ID_PORTLV_ACTIVE);
  297.          SetListviewDoubleClick (portlist,ID_PORTMORE);
  298.  
  299.          ShowPorts();
  300.  
  301.          SetWindowOpen (WI_Ports,portlist,ID_PORTEXIT);
  302.       }
  303.    } else if ((! state) && (WI_Ports)) {
  304.       SetWindowClose (WI_Ports,TRUE);
  305.  
  306.       FreePorts();
  307.  
  308.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Ports);
  309.       MUI_DisposeObject (WI_Ports);
  310.       WI_Ports = NULL;
  311.       portlist = NULL;
  312.    }
  313. }
  314.  
  315.